package com.heima.common.tess4j;

import lombok.Getter;
import lombok.Setter;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.awt.image.BufferedImage;
import java.io.File;

@Component
@Setter
@Getter
@ConfigurationProperties(prefix = "tess4j")  //使用的时候要添加配置文件
public class Tess4jUtil {

    private String dataPath ;
    private String language ;

    public String doOCR(BufferedImage bufferedImage) throws TesseractException {
        ITesseract iTesseract = new Tesseract();
        //字体库路径 路径里面不要有中文
        iTesseract.setDatapath(dataPath);
        //设置语言
        iTesseract.setLanguage(language);
        String s = iTesseract.doOCR(bufferedImage);
        System.out.println("图片识别结果："+s.replaceAll("\\r|\\n" , "-"));
        return s ;
    }

}
